#include <stdio.h>
#include <stdlib.h>
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */

int *sortedSquares(int *nums, int numsSize, int *returnSize)
{
    int *temp = (void *)malloc(numsSize * sizeof(int));
    for (int i = 0; i < numsSize; i++)
    {
        temp[i] = nums[i] * nums[i];
    }
    for (int i = 0; i < numsSize; i++)
    {
        int min = temp[i];
        for (int j = i + 1; j < numsSize; j++)
        {
            if (temp[j] < min)
            {
                int z = temp[j];
                min = temp[j];
                temp[j] = temp[i];
                temp[i] = z;
            }
        }
    }

    return temp;
}

int main()
{
    int nums[] = {-4, -1, 0, 3, 10};
    int numsSize = 5;
    int *returnSize = &numsSize;
    int *out = sortedSquares(nums, numsSize, returnSize);
    for (int i = 0; i < *returnSize; i++)
    {
        printf("%d ", out[i]);
    }
    free(out);
}